sap.ui.define([
    "sap/ui/core/mvc/Controller",
    "sap/ui/model/json/JSONModel"
],
    /**
     * @param {typeof sap.ui.core.mvc.Controller} Controller
     */
    function (Controller, JSONModel) {
        "use strict";

        return Controller.extend("c040.controller.Main", {
            onInit: function () {
                this.initRichTextEditor()

                var aVariousNumberData = [
                    { currency: "EUR", price: 2300.12 },
                    { currency: "EUR", price: 38 },
                    { currency: "JPY", price: 1928472 },
                    { currency: "JPY", price: 233.9385763 },
                    { currency: "USD", price: 125.02 },
                    { currency: "USD", price: 2125.02843 },
                    { currency: "CNY", price: 9283 },
                    { currency: "CNY", price: 235.0298 },
                    { currency: "KRW", price: 123.4567 },
                    { currency: "KRW", price: 235.0298 }

                ];

                var aBigNumberData = [
                    { currency: "USD", price: "12345678901234567890123" },
                    { currency: "USD", price: "123456789012345678901.23" }
                ];

                var expText = "The full text is displayed in place. Lorem ipsum dolor sit amet, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum.Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Lorem ipsum dolor sit amet, consetetur sadipscing elitr"


                var formatText = "<h3>subheader</h3>" +
                    "<p>link: <a href=\"//www.sap.com\" style=\"color:green; font-weight:600;\">link to sap.com</a> - links open in a new window.</p>" +
                    "<p>paragraph: <strong>strong</strong> and <em>emphasized</em>.</p>"

                var htmlText = "<div style='color: red;'><p>This is a simple HTML content.</p><button onclick='alert(&#39;Hello, UI5!&#39;);'>Click me</button></div>"

                var oModel = new JSONModel({
                    variousNumberDataModel: aVariousNumberData,
                    bigNumberDataModel: aBigNumberData,
                    expTextModel: expText,
                    formatTextModel: formatText,
                    htmlTextModel: htmlText

                });
                this.getView().setModel(oModel);

                this.getView().setModel(new JSONModel({ "name": "" }), "InputValue");
            },
            onClickShowTextArea: function () {
                sap.m.MessageToast.show("Textarea value: " + this.byId("textarea01").getValue());

            },
            handleLiveChange: function (oEvent) {
                var sValue = oEvent.getParameter("value");
                this.byId("getValue").setText(sValue);
            },
            initRichTextEditor: function () {
                var that = this
                sap.ui.require(["sap/ui/richtexteditor/RichTextEditor", "sap/ui/richtexteditor/library"],
                    function (RTE, library) {
                        var EditorType = library.EditorType;
                        that.oRichTextEditor = new RTE("myRTE", {
                            editorType: EditorType.TinyMCE6,
                            width: "100%",
                            height: "400px",
                            customToolbar: true,
                            showGroupFont: true,
                            showGroupLink: true,
                            showGroupInsert: true,
                            value: '',
                            ready: function () {
                                this.addButtonGroup("styles").addButtonGroup("table");
                                //控制工具栏
                                this.removeButtonGroup("font-style");
                                this.addButtonGroup({
                                    name: "font-style",
                                    visible: true,
                                    priority: 10,
                                    customToolbarPriority: 10,
                                    buttons: [
                                        "bold", "italic"
                                    ]
                                });
                            }
                        });

                        that.getView().byId("idVerticalLayout").addContent(that.oRichTextEditor);
                    });
            },
            onSaveRichText: function () {
                var oRichTextEditor = this.oRichTextEditor; // 使用您在initRichTextEditor函数中指定的ID
                var sValue = oRichTextEditor.getValue();
                sap.m.MessageToast.show(sValue);
            }
        });
    });
